package com.xhji.web.mvc.request;

import com.xhji.web.mvc.response.GenericResponse;
import com.xhji.web.mvc.response.ResponseDecorate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.HandlerMethod;

import javax.annotation.Resource;

@RestControllerAdvice
@Slf4j
public class RestControllerExceptionHandler {

    @Resource
    private ResponseDecorate responseDecorate;

    @ExceptionHandler(Exception.class)
    public GenericResponse<?> onError(Exception e, HandlerMethod method) {
        return responseDecorate.decorate(null,e,method.getMethod());
    }

}
